package com.tokaplot;

import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.StateListDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageButton;
import android.widget.RadioButton;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.app.TabActivity;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;

import android.util.Log;

public class LinePicker extends TabActivity implements OnTabChangeListener {

	private static final String TAG = "Dataplot";

	public final static String EXTRA_LINESTYLE = "com.cd.dataplot.Dataplot.LINESTYLE";
	public final static String EXTRA_LINECOLOUR = "com.cd.dataplot.Dataplot.EXTRA_LINECOLOUR";

	private int wStyle = 0;
	private int wColour = 0xFF000000;

	// Table data and callback
	String TabIds[] = {"tab1", "tab2"};

	private TabHost tabHost;
	private int tabSelected = -1;

	// Button bitmaps
	private Canvas c;
	private Path pLine;
	private Path pFill;

	private Bitmap [][][] bBmp_line = new Bitmap[4][5][2];
	private StateListDrawable bStates_line [][] = new StateListDrawable[4][5];

	private Bitmap [][][] bBmp_fill = new Bitmap[3][5][2];
	private StateListDrawable bStates_fill [][] = new StateListDrawable[3][5];

	public void onTabChanged(String tabId) {
		for (tabSelected = 0; tabSelected<TabIds.length && !tabId.equals(TabIds[tabSelected]); tabSelected++);
		Log.e(TAG, "Tab selected " + tabSelected);
	}

	public LinePicker() {
		super();
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setResult(RESULT_CANCELED);

		// Get passed style from intent
		Intent intent = getIntent();
		Bundle extras = intent.getExtras();
		if (extras != null) {
		    wStyle = extras.getInt(EXTRA_LINESTYLE, wStyle);
			wColour = extras.getInt(EXTRA_LINECOLOUR, wColour);
		}

		// Get bitmap height and width
		Resources res = getResources();
		int bWidth = (int)(res.getDimension(R.dimen.linepicker_button_width));
		int bHeight = (int)(res.getDimension(R.dimen.linepicker_button_height));

		// Create path
		pLine = new Path();
		pLine.moveTo(10.0f, 		0.50f*(float)bHeight);
		pLine.lineTo(0.333f*bWidth, 0.75f*(float)bHeight);
		pLine.lineTo(0.666f*bWidth, 0.25f*(float)bHeight);
		pLine.lineTo(bWidth-10.0f, 	0.50f*(float)bHeight);

		pFill = new Path();
		pFill.moveTo(10.0f, 		(float)bHeight-10.0f);
		pFill.lineTo(10.0f, 		0.50f*(float)bHeight);
		pFill.lineTo(0.333f*bWidth, 0.75f*(float)bHeight);
		pFill.lineTo(0.666f*bWidth, 0.25f*(float)bHeight);
		pFill.lineTo(bWidth-10.0f, 	0.50f*(float)bHeight);
		pFill.lineTo(bWidth-10.0f, 	(float)bHeight-10.0f);

		// Create selection bitmap
		Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
		p.setColor(0xFFFFFFFF);
		p.setStrokeWidth(2.0f);
		p.setStyle(Paint.Style.STROKE);

		c = new Canvas();
		Bitmap bSel = Bitmap.createBitmap(bWidth, bHeight, Bitmap.Config.ARGB_8888);
		bSel.eraseColor(0x00000000);
		c.setBitmap(bSel);
		c.drawRoundRect(new RectF(5.0f, 5.0f, (float)bWidth-5.0f, (float)bHeight-5.0f), 5.0f, 5.0f, p);

		// Create bitmaps and bitmap drawables
		int i, j;    	
		for (j = 0; j<4; j++)
			for (i = 0; i<5; i++) {

				// Selected
				bBmp_line[j][i][0] = Bitmap.createBitmap(bSel);

				// Unselected
				bBmp_line[j][i][1] = Bitmap.createBitmap(bWidth, bHeight, Bitmap.Config.ARGB_8888);
				bBmp_line[j][i][1].eraseColor(0x00000000);

				bStates_line[j][i] = new StateListDrawable();
				bStates_line[j][i].addState(new int[] { android.R.attr.state_checked}, new BitmapDrawable(bBmp_line[j][i][0]));
				bStates_line[j][i].addState(new int[] {-android.R.attr.state_checked}, new BitmapDrawable(bBmp_line[j][i][1]));
			}    

		for (j = 0; j<3; j++)
			for (i = 0; i<5; i++) {

				// Selected
				bBmp_fill[j][i][0] = Bitmap.createBitmap(bSel);

				// Unselected
				bBmp_fill[j][i][1] = Bitmap.createBitmap(bWidth, bHeight, Bitmap.Config.ARGB_8888);
				bBmp_fill[j][i][1].eraseColor(0x00000000);

				bStates_fill[j][i] = new StateListDrawable();
				bStates_fill[j][i].addState(new int[] { android.R.attr.state_checked}, new BitmapDrawable(bBmp_fill[j][i][0]));
				bStates_fill[j][i].addState(new int[] {-android.R.attr.state_checked}, new BitmapDrawable(bBmp_fill[j][i][1]));
			}

		// Update
		setBitmaps(wColour);

		// Setup view
		setContentView(R.layout.linepicker);

		// Create tabs
		tabHost = getTabHost();
		tabHost.setOnTabChangedListener(this);

		for (i = 0; i<TabIds.length; i++) {
			TabHost.TabSpec tabSpec = tabHost.newTabSpec(TabIds[i]);

			ImageView tabView = new ImageView(this);	        
			tabView.setBackgroundDrawable(getResources().getDrawable(R.xml.tab_background_selector));

			// Set up tab
			switch (i) {
			case 0: { tabSpec.setContent(R.id.linepicker_tab1); tabView.setImageDrawable(getResources().getDrawable(R.drawable.style1)); } break;
			case 1: { tabSpec.setContent(R.id.linepicker_tab2); tabView.setImageDrawable(getResources().getDrawable(R.drawable.style2)); } break;
			}
			tabSpec.setIndicator(tabView);
			tabHost.addTab(tabSpec);
		}

		// Select tab
		if (LineRender.getStyleType(wStyle) == 1)
			tabHost.setCurrentTab(1);
		else
			tabHost.setCurrentTab(0);

		// Set selector bitmaps
		updateBitmaps();
		
		RadioGroup rgl1 = (RadioGroup)findViewById(R.id.linepicker_group_line_1);
		RadioGroup rgl2 = (RadioGroup)findViewById(R.id.linepicker_group_line_2);
		RadioGroup rgl3 = (RadioGroup)findViewById(R.id.linepicker_group_line_3);
		RadioGroup rgl4 = (RadioGroup)findViewById(R.id.linepicker_group_line_4);

		RadioGroup rgf1 = (RadioGroup)findViewById(R.id.linepicker_group_fill_1);
		RadioGroup rgf2 = (RadioGroup)findViewById(R.id.linepicker_group_fill_2);
		RadioGroup rgf3 = (RadioGroup)findViewById(R.id.linepicker_group_fill_3);

		// Set XOR
		if (LineRender.getStyleCompo(wStyle) == 1) 
			((CheckBox)findViewById(R.id.linepicker_xor)).setChecked(true);
		else
			((CheckBox)findViewById(R.id.linepicker_xor)).setChecked(false);

		// Set colour picker
		((ImageButton)findViewById(R.id.linepicker_col1)).getBackground().setColorFilter(wColour, PorterDuff.Mode.MULTIPLY);
		findViewById(R.id.linepicker_col1).setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				new DialogColour(LinePicker.this, wColour, new DialogColour.OnColourChangedListener() {

					public void colourChanged(int colour) {
					    wColour = colour;
						((ImageButton)findViewById(R.id.linepicker_col1)).getBackground().setColorFilter(wColour, PorterDuff.Mode.MULTIPLY);
						setBitmaps(wColour);
						updateBitmaps();
					}
				}).show();
			}
		}); 

		// Set selection
		switch (LineRender.getStyleType(wStyle)) {
		case 0:

			// Line width
			switch (LineRender.getStyleWidth(wStyle)) {
			case 1:  rgl1.check(R.id.linepicker_line_1_2); break;
			case 2:  rgl1.check(R.id.linepicker_line_1_3); break;
			case 3:  rgl1.check(R.id.linepicker_line_1_4); break;
			case 4:  rgl1.check(R.id.linepicker_line_1_5); break;
			default: rgl1.check(R.id.linepicker_line_1_1); break;
			}

			// Line dashes
			switch (LineRender.getStyleDash(wStyle)) {
			case 1:  rgl2.check(R.id.linepicker_line_2_2); break;
			case 2:  rgl2.check(R.id.linepicker_line_2_3); break;
			case 3:  rgl2.check(R.id.linepicker_line_2_4); break;
			case 4:  rgl2.check(R.id.linepicker_line_2_5); break;
			default: rgl2.check(R.id.linepicker_line_2_1); break;
			}

			// Line effect
			switch (LineRender.getStyleEffect(wStyle)) {
			case 1:  rgl3.check(R.id.linepicker_line_3_2); break;
			case 2:  rgl3.check(R.id.linepicker_line_3_3); break;
			case 3:  rgl3.check(R.id.linepicker_line_3_4); break;
			case 4:  rgl3.check(R.id.linepicker_line_3_5); break;
			default: rgl3.check(R.id.linepicker_line_3_1); break;
			}

			// Line curve
			switch (LineRender.getStyleCurve(wStyle)) {
			case 1:  rgl4.check(R.id.linepicker_line_4_2); break;
			case 2:  rgl4.check(R.id.linepicker_line_4_3); break;
			case 3:  rgl4.check(R.id.linepicker_line_4_4); break;
			case 4:  rgl4.check(R.id.linepicker_line_4_5); break;
			default: rgl4.check(R.id.linepicker_line_4_1); break;
			}
			break;

		case 1:

			// Fill effect
			switch (LineRender.getStyleEffect(wStyle)) {
			case 1:  rgf1.check(R.id.linepicker_fill_1_2); break;
			case 2:  rgf1.check(R.id.linepicker_fill_1_3); break;
			case 3:  rgf1.check(R.id.linepicker_fill_1_4); break;
			case 4:  rgf1.check(R.id.linepicker_fill_1_5); break;
			default: rgf1.check(R.id.linepicker_fill_1_1); break;
			}

			// Fill gradient
			switch (LineRender.getStyleGrad(wStyle)) {
			case 1:  rgf2.check(R.id.linepicker_fill_2_2); break;
			case 2:  rgf2.check(R.id.linepicker_fill_2_3); break;
			case 3:  rgf2.check(R.id.linepicker_fill_2_4); break;
			case 4:  rgf2.check(R.id.linepicker_fill_2_5); break;
			default: rgf2.check(R.id.linepicker_fill_2_1); break;
			}

			// Fill curve
			switch (LineRender.getStyleCurve(wStyle)) {
			case 1:  rgf3.check(R.id.linepicker_fill_3_2); break;
			case 2:  rgf3.check(R.id.linepicker_fill_3_3); break;
			case 3:  rgf3.check(R.id.linepicker_fill_3_4); break;
			case 4:  rgf3.check(R.id.linepicker_fill_3_5); break;
			default: rgf3.check(R.id.linepicker_fill_3_1); break;
			}
			break;

		}

		// Set listeners
		findViewById(R.id.linepicker_done).setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) { 

				int st_type 	= 0;
				int st_width 	= 0;
				int st_dash 	= 0;
				int st_effect 	= 0;
				int st_curve 	= 0;
				int st_grad 	= 0;
				int st_compo	= 0;

				// Get XOR
				if (((CheckBox)findViewById(R.id.linepicker_xor)).isChecked())
					st_compo = 1;
				else
					st_compo = 0;

				RadioGroup rgl1 = (RadioGroup)findViewById(R.id.linepicker_group_line_1);
				RadioGroup rgl2 = (RadioGroup)findViewById(R.id.linepicker_group_line_2);
				RadioGroup rgl3 = (RadioGroup)findViewById(R.id.linepicker_group_line_3);
				RadioGroup rgl4 = (RadioGroup)findViewById(R.id.linepicker_group_line_4);

				RadioGroup rgf1 = (RadioGroup)findViewById(R.id.linepicker_group_fill_1);
				RadioGroup rgf2 = (RadioGroup)findViewById(R.id.linepicker_group_fill_2);
				RadioGroup rgf3 = (RadioGroup)findViewById(R.id.linepicker_group_fill_3);

				// Get selection
				switch (tabSelected) {
				case 0:

					// Line style
					st_type = 0;
					st_grad = 0;

					// Line width
					switch (rgl1.getCheckedRadioButtonId()) {
					case R.id.linepicker_line_1_1: st_width = 0; break;
					case R.id.linepicker_line_1_2: st_width = 1; break;
					case R.id.linepicker_line_1_3: st_width = 2; break;
					case R.id.linepicker_line_1_4: st_width = 3; break;
					case R.id.linepicker_line_1_5: st_width = 4; break;                			
					}

					// Line dashes
					switch (rgl2.getCheckedRadioButtonId()) {
					case R.id.linepicker_line_2_1: st_dash = 0; break;
					case R.id.linepicker_line_2_2: st_dash = 1; break;
					case R.id.linepicker_line_2_3: st_dash = 2; break;
					case R.id.linepicker_line_2_4: st_dash = 3; break;
					case R.id.linepicker_line_2_5: st_dash = 4; break;                			
					}

					// Line effect
					switch (rgl3.getCheckedRadioButtonId()) {
					case R.id.linepicker_line_3_1: st_effect = 0; break;
					case R.id.linepicker_line_3_2: st_effect = 1; break;
					case R.id.linepicker_line_3_3: st_effect = 2; break;
					case R.id.linepicker_line_3_4: st_effect = 3; break;
					case R.id.linepicker_line_3_5: st_effect = 4; break;                			
					}

					// Line curve
					switch (rgl4.getCheckedRadioButtonId()) {
					case R.id.linepicker_line_4_1: st_curve = 0; break;
					case R.id.linepicker_line_4_2: st_curve = 1; break;
					case R.id.linepicker_line_4_3: st_curve = 2; break;
					case R.id.linepicker_line_4_4: st_curve = 3; break;
					case R.id.linepicker_line_4_5: st_curve = 4; break;                			
					}
					break;

				case 1:

					// Fill style
					st_type = 1;
					st_dash = 0;
					st_width = 2;

					// Line effect
					switch (rgf1.getCheckedRadioButtonId()) {
					case R.id.linepicker_fill_1_1: st_effect = 0; break;
					case R.id.linepicker_fill_1_2: st_effect = 1; break;
					case R.id.linepicker_fill_1_3: st_effect = 2; break;
					case R.id.linepicker_fill_1_4: st_effect = 3; break;
					case R.id.linepicker_fill_1_5: st_effect = 4; break;                			
					}

					// Line gradient
					switch (rgf2.getCheckedRadioButtonId()) {
					case R.id.linepicker_fill_2_1: st_grad = 0; break;
					case R.id.linepicker_fill_2_2: st_grad = 1; break;
					case R.id.linepicker_fill_2_3: st_grad = 2; break;
					case R.id.linepicker_fill_2_4: st_grad = 3; break;
					case R.id.linepicker_fill_2_5: st_grad = 4; break;                			
					}

					// Line curve
					switch (rgf3.getCheckedRadioButtonId()) {
					case R.id.linepicker_fill_3_1: st_curve = 0; break;
					case R.id.linepicker_fill_3_2: st_curve = 1; break;
					case R.id.linepicker_fill_3_3: st_curve = 2; break;
					case R.id.linepicker_fill_3_4: st_curve = 3; break;
					case R.id.linepicker_fill_3_5: st_curve = 4; break;                			
					}
					break;
				}

				// Build style
				wStyle = LineRender.makeStyle(st_compo, st_grad, st_curve, st_effect, st_dash, st_width, st_type);

				// Pass back to widget
				Intent resultIntent = new Intent();
				resultIntent.putExtra(EXTRA_LINESTYLE, wStyle);
				resultIntent.putExtra(EXTRA_LINECOLOUR, wColour);
				setResult(RESULT_OK, resultIntent);

				finish();
			}
		});

		findViewById(R.id.linepicker_cancel).setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {

				// Pass back to widget
				setResult(RESULT_CANCELED);

				finish();
			}
		});
	}

	void setBitmaps(int col) {

		// Draw styles
		for (int k = 0; k<2; k++) {
			c.setBitmap(bBmp_line[0][0][k]); LineRender.renderPath(c, pLine, col, LineRender.makeStyle(0, 0, 0, 0, 0, 0, 0), Paint.ANTI_ALIAS_FLAG);
			c.setBitmap(bBmp_line[0][1][k]); LineRender.renderPath(c, pLine, col, LineRender.makeStyle(0, 0, 0, 0, 0, 1, 0), Paint.ANTI_ALIAS_FLAG);
			c.setBitmap(bBmp_line[0][2][k]); LineRender.renderPath(c, pLine, col, LineRender.makeStyle(0, 0, 0, 0, 0, 2, 0), Paint.ANTI_ALIAS_FLAG);
			c.setBitmap(bBmp_line[0][3][k]); LineRender.renderPath(c, pLine, col, LineRender.makeStyle(0, 0, 0, 0, 0, 3, 0), Paint.ANTI_ALIAS_FLAG);
			c.setBitmap(bBmp_line[0][4][k]); LineRender.renderPath(c, pLine, col, LineRender.makeStyle(0, 0, 0, 0, 0, 4, 0), Paint.ANTI_ALIAS_FLAG);

			c.setBitmap(bBmp_line[1][0][k]); LineRender.renderPath(c, pLine, col, LineRender.makeStyle(0, 0, 0, 0, 0, 1, 0), Paint.ANTI_ALIAS_FLAG);
			c.setBitmap(bBmp_line[1][1][k]); LineRender.renderPath(c, pLine, col, LineRender.makeStyle(0, 0, 0, 0, 1, 1, 0), Paint.ANTI_ALIAS_FLAG);
			c.setBitmap(bBmp_line[1][2][k]); LineRender.renderPath(c, pLine, col, LineRender.makeStyle(0, 0, 0, 0, 2, 1, 0), Paint.ANTI_ALIAS_FLAG);
			c.setBitmap(bBmp_line[1][3][k]); LineRender.renderPath(c, pLine, col, LineRender.makeStyle(0, 0, 0, 0, 3, 1, 0), Paint.ANTI_ALIAS_FLAG);
			c.setBitmap(bBmp_line[1][4][k]); LineRender.renderPath(c, pLine, col, LineRender.makeStyle(0, 0, 0, 0, 4, 1, 0), Paint.ANTI_ALIAS_FLAG);

			c.setBitmap(bBmp_line[2][0][k]); LineRender.renderPath(c, pLine, col, LineRender.makeStyle(0, 0, 0, 0, 0, 2, 0), Paint.ANTI_ALIAS_FLAG);
			c.setBitmap(bBmp_line[2][1][k]); LineRender.renderPath(c, pLine, col, LineRender.makeStyle(0, 0, 0, 1, 0, 2, 0), Paint.ANTI_ALIAS_FLAG);
			c.setBitmap(bBmp_line[2][2][k]); LineRender.renderPath(c, pLine, col, LineRender.makeStyle(0, 0, 0, 2, 0, 2, 0), Paint.ANTI_ALIAS_FLAG);
			c.setBitmap(bBmp_line[2][3][k]); LineRender.renderPath(c, pLine, col, LineRender.makeStyle(0, 0, 0, 3, 0, 2, 0), Paint.ANTI_ALIAS_FLAG);
			c.setBitmap(bBmp_line[2][4][k]); LineRender.renderPath(c, pLine, col, LineRender.makeStyle(0, 0, 0, 4, 0, 2, 0), Paint.ANTI_ALIAS_FLAG);

			c.setBitmap(bBmp_line[3][0][k]); LineRender.renderPath(c, pLine, col, LineRender.makeStyle(0, 0, 0, 0, 0, 1, 0), Paint.ANTI_ALIAS_FLAG);
			c.setBitmap(bBmp_line[3][1][k]); LineRender.renderPath(c, pLine, col, LineRender.makeStyle(0, 0, 1, 0, 0, 1, 0), Paint.ANTI_ALIAS_FLAG);
			c.setBitmap(bBmp_line[3][2][k]); LineRender.renderPath(c, pLine, col, LineRender.makeStyle(0, 0, 2, 0, 0, 1, 0), Paint.ANTI_ALIAS_FLAG);
			c.setBitmap(bBmp_line[3][3][k]); LineRender.renderPath(c, pLine, col, LineRender.makeStyle(0, 0, 3, 0, 0, 1, 0), Paint.ANTI_ALIAS_FLAG);
			c.setBitmap(bBmp_line[3][4][k]); LineRender.renderPath(c, pLine, col, LineRender.makeStyle(0, 0, 4, 0, 0, 1, 0), Paint.ANTI_ALIAS_FLAG);

			c.setBitmap(bBmp_fill[0][0][k]); LineRender.renderPath(c, pFill, col, LineRender.makeStyle(0, 0, 0, 0, 0, 2, 1), Paint.ANTI_ALIAS_FLAG);
			c.setBitmap(bBmp_fill[0][1][k]); LineRender.renderPath(c, pFill, col, LineRender.makeStyle(0, 0, 0, 1, 0, 2, 1), Paint.ANTI_ALIAS_FLAG);
			c.setBitmap(bBmp_fill[0][2][k]); LineRender.renderPath(c, pFill, col, LineRender.makeStyle(0, 0, 0, 2, 0, 2, 1), Paint.ANTI_ALIAS_FLAG);
			c.setBitmap(bBmp_fill[0][3][k]); LineRender.renderPath(c, pFill, col, LineRender.makeStyle(0, 0, 0, 3, 0, 2, 1), Paint.ANTI_ALIAS_FLAG);
			c.setBitmap(bBmp_fill[0][4][k]); LineRender.renderPath(c, pFill, col, LineRender.makeStyle(0, 0, 0, 4, 0, 2, 1), Paint.ANTI_ALIAS_FLAG);

			c.setBitmap(bBmp_fill[1][0][k]); LineRender.renderPath(c, pFill, col, LineRender.makeStyle(0, 0, 0, 0, 0, 1, 1), Paint.ANTI_ALIAS_FLAG);
			c.setBitmap(bBmp_fill[1][1][k]); LineRender.renderPath(c, pFill, col, LineRender.makeStyle(0, 1, 0, 0, 0, 1, 1), Paint.ANTI_ALIAS_FLAG);
			c.setBitmap(bBmp_fill[1][2][k]); LineRender.renderPath(c, pFill, col, LineRender.makeStyle(0, 2, 0, 0, 0, 1, 1), Paint.ANTI_ALIAS_FLAG);
			c.setBitmap(bBmp_fill[1][3][k]); LineRender.renderPath(c, pFill, col, LineRender.makeStyle(0, 3, 0, 0, 0, 1, 1), Paint.ANTI_ALIAS_FLAG);
			c.setBitmap(bBmp_fill[1][4][k]); LineRender.renderPath(c, pFill, col, LineRender.makeStyle(0, 4, 0, 0, 0, 1, 1), Paint.ANTI_ALIAS_FLAG);

			c.setBitmap(bBmp_fill[2][0][k]); LineRender.renderPath(c, pFill, col, LineRender.makeStyle(0, 0, 0, 0, 0, 1, 1), Paint.ANTI_ALIAS_FLAG);
			c.setBitmap(bBmp_fill[2][1][k]); LineRender.renderPath(c, pFill, col, LineRender.makeStyle(0, 0, 1, 0, 0, 1, 1), Paint.ANTI_ALIAS_FLAG);
			c.setBitmap(bBmp_fill[2][2][k]); LineRender.renderPath(c, pFill, col, LineRender.makeStyle(0, 0, 2, 0, 0, 1, 1), Paint.ANTI_ALIAS_FLAG);
			c.setBitmap(bBmp_fill[2][3][k]); LineRender.renderPath(c, pFill, col, LineRender.makeStyle(0, 0, 3, 0, 0, 1, 1), Paint.ANTI_ALIAS_FLAG);
			c.setBitmap(bBmp_fill[2][4][k]); LineRender.renderPath(c, pFill, col, LineRender.makeStyle(0, 0, 4, 0, 0, 1, 1), Paint.ANTI_ALIAS_FLAG);

		} 
	}

	void updateBitmaps () {
		
		// Set button images		
		((RadioButton)findViewById(R.id.linepicker_line_1_1)).setBackgroundDrawable(bStates_line[0][0]);
		((RadioButton)findViewById(R.id.linepicker_line_1_2)).setBackgroundDrawable(bStates_line[0][1]);
		((RadioButton)findViewById(R.id.linepicker_line_1_3)).setBackgroundDrawable(bStates_line[0][2]);
		((RadioButton)findViewById(R.id.linepicker_line_1_4)).setBackgroundDrawable(bStates_line[0][3]);
		((RadioButton)findViewById(R.id.linepicker_line_1_5)).setBackgroundDrawable(bStates_line[0][4]);

		((RadioButton)findViewById(R.id.linepicker_line_2_1)).setBackgroundDrawable(bStates_line[1][0]);
		((RadioButton)findViewById(R.id.linepicker_line_2_2)).setBackgroundDrawable(bStates_line[1][1]);
		((RadioButton)findViewById(R.id.linepicker_line_2_3)).setBackgroundDrawable(bStates_line[1][2]);
		((RadioButton)findViewById(R.id.linepicker_line_2_4)).setBackgroundDrawable(bStates_line[1][3]);
		((RadioButton)findViewById(R.id.linepicker_line_2_5)).setBackgroundDrawable(bStates_line[1][4]);

		((RadioButton)findViewById(R.id.linepicker_line_3_1)).setBackgroundDrawable(bStates_line[2][0]);
		((RadioButton)findViewById(R.id.linepicker_line_3_2)).setBackgroundDrawable(bStates_line[2][1]);
		((RadioButton)findViewById(R.id.linepicker_line_3_3)).setBackgroundDrawable(bStates_line[2][2]);
		((RadioButton)findViewById(R.id.linepicker_line_3_4)).setBackgroundDrawable(bStates_line[2][3]);
		((RadioButton)findViewById(R.id.linepicker_line_3_5)).setBackgroundDrawable(bStates_line[2][4]);

		((RadioButton)findViewById(R.id.linepicker_line_4_1)).setBackgroundDrawable(bStates_line[3][0]);
		((RadioButton)findViewById(R.id.linepicker_line_4_2)).setBackgroundDrawable(bStates_line[3][1]);
		((RadioButton)findViewById(R.id.linepicker_line_4_3)).setBackgroundDrawable(bStates_line[3][2]);
		((RadioButton)findViewById(R.id.linepicker_line_4_4)).setBackgroundDrawable(bStates_line[3][3]);
		((RadioButton)findViewById(R.id.linepicker_line_4_5)).setBackgroundDrawable(bStates_line[3][4]);

		((RadioButton)findViewById(R.id.linepicker_fill_1_1)).setBackgroundDrawable(bStates_fill[0][0]);
		((RadioButton)findViewById(R.id.linepicker_fill_1_2)).setBackgroundDrawable(bStates_fill[0][1]);
		((RadioButton)findViewById(R.id.linepicker_fill_1_3)).setBackgroundDrawable(bStates_fill[0][2]);
		((RadioButton)findViewById(R.id.linepicker_fill_1_4)).setBackgroundDrawable(bStates_fill[0][3]);
		((RadioButton)findViewById(R.id.linepicker_fill_1_5)).setBackgroundDrawable(bStates_fill[0][4]);

		((RadioButton)findViewById(R.id.linepicker_fill_2_1)).setBackgroundDrawable(bStates_fill[1][0]);
		((RadioButton)findViewById(R.id.linepicker_fill_2_2)).setBackgroundDrawable(bStates_fill[1][1]);
		((RadioButton)findViewById(R.id.linepicker_fill_2_3)).setBackgroundDrawable(bStates_fill[1][2]);
		((RadioButton)findViewById(R.id.linepicker_fill_2_4)).setBackgroundDrawable(bStates_fill[1][3]);
		((RadioButton)findViewById(R.id.linepicker_fill_2_5)).setBackgroundDrawable(bStates_fill[1][4]);

		((RadioButton)findViewById(R.id.linepicker_fill_3_1)).setBackgroundDrawable(bStates_fill[2][0]);
		((RadioButton)findViewById(R.id.linepicker_fill_3_2)).setBackgroundDrawable(bStates_fill[2][1]);
		((RadioButton)findViewById(R.id.linepicker_fill_3_3)).setBackgroundDrawable(bStates_fill[2][2]);
		((RadioButton)findViewById(R.id.linepicker_fill_3_4)).setBackgroundDrawable(bStates_fill[2][3]);
		((RadioButton)findViewById(R.id.linepicker_fill_3_5)).setBackgroundDrawable(bStates_fill[2][4]);  
		
		// Update view
		((RadioButton)findViewById(R.id.linepicker_line_1_1)).invalidate();
		((RadioButton)findViewById(R.id.linepicker_line_1_2)).invalidate();
		((RadioButton)findViewById(R.id.linepicker_line_1_3)).invalidate();
		((RadioButton)findViewById(R.id.linepicker_line_1_4)).invalidate();
		((RadioButton)findViewById(R.id.linepicker_line_1_5)).invalidate();

		((RadioButton)findViewById(R.id.linepicker_line_2_1)).invalidate();
		((RadioButton)findViewById(R.id.linepicker_line_2_2)).invalidate();
		((RadioButton)findViewById(R.id.linepicker_line_2_3)).invalidate();
		((RadioButton)findViewById(R.id.linepicker_line_2_4)).invalidate();
		((RadioButton)findViewById(R.id.linepicker_line_2_5)).invalidate();

		((RadioButton)findViewById(R.id.linepicker_line_3_1)).invalidate();
		((RadioButton)findViewById(R.id.linepicker_line_3_2)).invalidate();
		((RadioButton)findViewById(R.id.linepicker_line_3_3)).invalidate();
		((RadioButton)findViewById(R.id.linepicker_line_3_4)).invalidate();
		((RadioButton)findViewById(R.id.linepicker_line_3_5)).invalidate();

		((RadioButton)findViewById(R.id.linepicker_line_4_1)).invalidate();
		((RadioButton)findViewById(R.id.linepicker_line_4_2)).invalidate();
		((RadioButton)findViewById(R.id.linepicker_line_4_3)).invalidate();
		((RadioButton)findViewById(R.id.linepicker_line_4_4)).invalidate();
		((RadioButton)findViewById(R.id.linepicker_line_4_5)).invalidate();		
		
		((RadioButton)findViewById(R.id.linepicker_fill_1_1)).invalidate();		
		((RadioButton)findViewById(R.id.linepicker_fill_1_2)).invalidate();		
		((RadioButton)findViewById(R.id.linepicker_fill_1_3)).invalidate();		
		((RadioButton)findViewById(R.id.linepicker_fill_1_4)).invalidate();		
		((RadioButton)findViewById(R.id.linepicker_fill_1_5)).invalidate();		

		((RadioButton)findViewById(R.id.linepicker_fill_2_1)).invalidate();		
		((RadioButton)findViewById(R.id.linepicker_fill_2_2)).invalidate();		
		((RadioButton)findViewById(R.id.linepicker_fill_2_3)).invalidate();		
		((RadioButton)findViewById(R.id.linepicker_fill_2_4)).invalidate();
		((RadioButton)findViewById(R.id.linepicker_fill_2_5)).invalidate();

		((RadioButton)findViewById(R.id.linepicker_fill_3_1)).invalidate();
		((RadioButton)findViewById(R.id.linepicker_fill_3_2)).invalidate();
		((RadioButton)findViewById(R.id.linepicker_fill_3_3)).invalidate();
		((RadioButton)findViewById(R.id.linepicker_fill_3_4)).invalidate();
		((RadioButton)findViewById(R.id.linepicker_fill_3_5)).invalidate();
	}
}
